package com.lab.web.controller.biz;

import com.lab.common.annotation.Log;
import com.lab.common.core.controller.BaseController;
import com.lab.common.core.domain.AjaxResult;
import com.lab.common.core.domain.model.LoginUser;
import com.lab.common.core.page.TableDataInfo;
import com.lab.common.enums.BusinessType;
import com.lab.common.utils.poi.ExcelUtil;
import com.lab.system.domain.ExperimentCourse;
import com.lab.system.domain.Lab;
import com.lab.system.service.IExperimentCourseService;
import com.lab.system.service.ILabService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 实验课程Controller
 *
 * @author cf
 * @date 2025-02-10
 */
@RestController
@RequestMapping("/biz/course")
public class ExperimentCourseController extends BaseController {
    @Autowired
    private IExperimentCourseService experimentCourseService;

    /**
     * 查询实验课程列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ExperimentCourse experimentCourse) {
        startPage();
        LoginUser loginUser = getLoginUser();
        List<ExperimentCourse> list = experimentCourseService.selectExperimentCourseList(experimentCourse,loginUser);
        return getDataTable(list);
    }

    /**
     * 导出实验课程列表
     */
    @PreAuthorize("@ss.hasPermi('biz:course:export')")
    @Log(title = "实验课程", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExperimentCourse experimentCourse) {
        List<ExperimentCourse> list = experimentCourseService.selectExperimentCourseList(experimentCourse,getLoginUser());
        ExcelUtil<ExperimentCourse> util = new ExcelUtil<ExperimentCourse>(ExperimentCourse.class);
        util.exportExcel(response, list, "实验课程数据");
    }

    /**
     * 获取实验课程详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(experimentCourseService.selectExperimentCourseById(id));
    }

    /**
     * 新增实验课程
     */
    @PreAuthorize("@ss.hasPermi('biz:course:add')")
    @Log(title = "实验课程", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExperimentCourse experimentCourse) {
        return toAjax(experimentCourseService.insertExperimentCourse(experimentCourse));
    }

    /**
     * 修改实验课程
     */
    @PreAuthorize("@ss.hasPermi('biz:course:edit')")
    @Log(title = "实验课程", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExperimentCourse experimentCourse) {
        return toAjax(experimentCourseService.updateExperimentCourse(experimentCourse));
    }

    /**
     * 删除实验课程
     */
    @PreAuthorize("@ss.hasPermi('biz:course:remove')")
    @Log(title = "实验课程", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(experimentCourseService.deleteExperimentCourseByIds(ids));
    }
}
